<?php
$this->headTitle($this->translator('review_page_title'));

    $this->headScript()
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.tools/jquery.tools.js')
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
        ;

?>
<style type="text/css">
    .cart table{
        width: 100%;
        border-top: 0px;
        border-bottom: 0px;
    }
    .cart .caption td{
        font-weight: bold;
        background: #BCBBB9;
    }
    .cart tr.caption:hover td{
        font-weight: bold;
        background: #BCBBB9;
    }
    .cart tbody tr:hover td{
        background: #EFEDED;
    }
    .inline_block{
        display: inline-block;
        width: 100%;
    }
    .inline_block .col_33{
        float:left;
        width:33.3%;
    }
    .inline_block .col_33 input{
        cursor: pointer;
    }
    .clear_fix{
        clear: both;
    }
    .cart_bottom{
        margin-bottom: 10px;
    }
    .cart .amount div label{
        font-weight: bold;
    }
    .cart .amount div label.error{
        font-weight: normal;
        color: #FF0000;
    }
    .tooltip {
        display:none;
        background:#BCBBB9;
        height:auto;
        width:200px;
        padding:10px;
    }
    .t_bizprofile_register label{
        text-align:left;
        font-weight:bold;
    }
    tbody td {
    	vertical-align: top;
    }
</style>
<?php
    $skin_url = $this->APP_STATIC_SERVER . '/skins/'. $this->APP_TEMPLATE . '/'. $this->APP_SKIN;
?>
<div class="grid_12">
    <div class="grid_8 alpha">
        <?php
            /**
            * Cart detail to view
            **/
            $cartDetails = $this->cartDetails;
        ?>
        <?php if(count($cartDetails) <= 0):?>
        <div class="cart">
	    	<table>
	    		<tr class="caption">
	            	<td width="20%"><?php echo $this->translator('cart_item_image');?></td>
	                <td width="25%"><?php echo $this->translator('cart_item_name');?></td>
	                <td width="20%"><?php echo $this->translator('cart_item_price');?></td>
	                <td width="15%"><?php echo $this->translator('cart_item_quantity');?></td>
	                <td width="20%"><?php echo $this->translator('cart_item_subtotal');?></td>
	            </tr>
	            <tr>
	            	<td colspan="5"><?php echo $this->translator('not_found_item');?></td>
	            </tr>
			</table>
			<div class="cart_bottom"></div>
	        <div style="text-align:right;" class="inline_block cart_bottom amount">
	            <div><label><?php echo $this->translator('cart_subtotal_amount')?></label>: 0</div>
	            <div><label><?php echo $this->translator('cart_shipping_amount')?></label>: 0</div>
	            <div><label><?php echo $this->translator('cart_total_amount')?></label>: 0</div>
	        </div>		
		</div>		
        <?php else:?>
        <form action="" method="POST" id="orderForm">
            <?php foreach($this->arrayEnterpriseId as $r_id):?>

                <?php
                    $arrayEnterpriseInfo = $this->arrayEnterpriseInfo[$r_id];
                    $arrProductsSorted =  $this->arrProductsSorted[$r_id];
                    $shipping_priceSorted =  $this->shipping_priceSorted[$r_id];
                    $subtotalSorted =  $this->subtotalSorted[$r_id];
                    $arrAllAtValSorted =  $this->arrAllAtValSorted[$r_id];
                    $arrayCartSorted =  $this->arrayCartSorted[$r_id];
                ?>

            <div class="cart">

                <div class="box subcolumns">
                    <div class="cufon_title">
                        <div class="inner">
                            <h3>
                                <?php echo $this->translator('cart_title_guide')?>:
                                <?php
                                    $arrRouteEnterprise = array(
                                        'enterprise_id' => $arrayEnterpriseInfo->id,
                                        'enterprise_name' => Tomato_Utility_String::removeSign($arrayEnterpriseInfo->company_name_en, '-', true)
                                    );
                                    $enterpriseName = ($this->lang == 'vi_VN')?$arrayEnterpriseInfo->company_name_vn:$arrayEnterpriseInfo->company_name_en;
                                ?>
                                <a href="<?php echo $this->url($arrRouteEnterprise, 'bizprofile_enterprise_index'); ?>"><?php echo $enterpriseName;?></a>
                            </h3>
                        </div>
                    </div>
                </div>

                <table>
                    <tr class="caption">
                        <td width="20%"><?php echo $this->translator('cart_item_image');?></td>
                        <td width="25%"><?php echo $this->translator('cart_item_name');?></td>
                        <td width="20%"><?php echo $this->translator('cart_item_price');?></td>
                        <td width="15%"><?php echo $this->translator('cart_item_quantity');?></td>
                        <td width="20%"><?php echo $this->translator('cart_item_subtotal');?></td>
                    </tr>
                    <?php

                    ?>
                    <?php foreach($arrayCartSorted as $d_cart):?>
                    <?php
                        /**
                        * Product info to view
                        **/
                        $product = $arrProductsSorted[$d_cart->id];
                        $p_currency = $product['p_currency'];

                        $arrAllAtVal = isset($arrAllAtValSorted[$d_cart->id])?$arrAllAtValSorted[$d_cart->id]:null;
                    ?>
                    <!--Hidden input-->
                    <input type="hidden" name="cart_id[]" value="<?php echo $d_cart->id;?>"/>

                    <tr>
                        <td><?php if($product['p_image']):?><img width="100" src="<?php echo $product['p_image'];?>" /><?php endif;?></td>
                        <td>
                            <?php echo ($d_cart->cart_parent_id)?'----':null;?><?php echo $product['p_name'];?>
                            <?php if($arrAllAtVal):?>
                            <br/><div class="view_detail">
                            	<?php echo ($d_cart->cart_parent_id)?'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;':null;?><img title="<?php echo $arrAllAtVal;?>" style="cursor:pointer" src="<?php echo $skin_url;?>/images/info_btn.png" />
                            	<label style="cursor:pointer" title="<?php echo $arrAllAtVal;?>"><?php echo $this->translator('cart_view_details')?></label>
                            </div>
                            <?php endif;?>
                        </td>
                        <td><?php echo $product['p_price'];?> <i><?php echo $product['p_currency'];?></i></td>
                        <td><?php echo $d_cart->cart_quantity;?></td>
                        <td><?php echo $product['total_price'];?> <i><?php echo $product['p_currency'];?></i></td>
                    </tr>
                    <?php endforeach;?>
                </table>
                <div class="cart_bottom"></div>
                <div class="inline_block cart_bottom amount">
                    <div style="width:65%; float:left;" class="inline_block cart_bottom amount">
                        <div>
                            <label><?php echo $this->translator('cart_payment_method')?></label>:
                            <select name="payment_method_<?php echo $r_id;?>" class="sb_payment" rel="<?php echo $r_id;?>">
                                <option value="">---</option>
                                <option value="cash"><?php echo $this->translator('cart_payment_cash');?></option>
                                <option value="bank_transfer"><?php echo $this->translator('cart_payment_bank');?></option>
                            </select>
                            <font style="color:red; padding-lef: 5px;">(*)</font>
                            
                            <br><br>
                            <label><?php echo $this->translator('cart_reception_method')?></label>:
                            <select name="reception_method_<?php echo $r_id;?>" id="reception_method_<?php echo $r_id;?>" class="sb_reception" rel="<?php echo $r_id;?>">
                                <option value="">---</option>
                                <option value="home_delivery"><?php echo $this->translator('cart_home_delivery');?></option>
                                <option value="self_pickup"><?php echo $this->translator('cart_self_pickup');?></option>
                            </select>
                            <font style="color:red; padding-lef: 5px;">(*)</font>
                        </div>
                        <div class="cart_bottom"></div>
                        <!--Enterprise payment info-->
                        <div style="display:none" id="payment_info_cash_<?php echo $r_id;?>">
                            <div>
                                <label><?php echo $this->translator('cart_contact_email')?></label>:
                                <?php echo $arrayEnterpriseInfo->contact_email;?>
                            </div>
                            <div>
                                <label><?php echo $this->translator('cart_contact_tel')?></label>:
                                <?php echo $arrayEnterpriseInfo->contact_tel;?>
                            </div>
                            <div>
                                <label><?php echo $this->translator('cart_contact_fax')?></label>:
                                <?php echo $arrayEnterpriseInfo->contact_fax;?>
                            </div>
                            <div>
                                <label><?php echo $this->translator('cart_contact_address')?></label>:
                                <?php echo $arrayEnterpriseInfo->contact_address;?>
                            </div>
                            <div>
                                <label><?php echo $this->translator('cart_currency')?></label>:
                                <?php echo $arrayEnterpriseInfo->currency;?>
                            </div>
                        </div>
                        <div style="display:none" id="payment_info_bank_transfer_<?php echo $r_id;?>">

                            <div><?php echo $this->translator('cart_enterprise_account');?> VND</div>
                            <hr/>
                            <div>
                                <label><?php echo $this->translator('cart_bank_name')?></label>:
                                <?php echo $arrayEnterpriseInfo->bank_name_vnd;?>
                            </div>
                            <div>
                                <label><?php echo $this->translator('cart_bank_account')?></label>:
                                <?php echo $arrayEnterpriseInfo->bank_account_vnd;?>
                            </div>
                            <div>
                                <label><?php echo $this->translator('cart_bank_account_owner')?></label>:
                                <?php echo $arrayEnterpriseInfo->bank_account_owner_vnd;?>
                            </div>

                            <div class="cart_bottom"></div>

                            <div><?php echo $this->translator('cart_enterprise_account');?> USD</div>
                            <hr/>
                            <div>
                                <label><?php echo $this->translator('cart_bank_name')?></label>:
                                <?php echo $arrayEnterpriseInfo->bank_name_usd;?>
                            </div>
                            <div>
                                <label><?php echo $this->translator('cart_bank_account')?></label>:
                                <?php echo $arrayEnterpriseInfo->bank_account_usd;?>
                            </div>
                            <div>
                                <label><?php echo $this->translator('cart_bank_account_owner')?></label>:
                                <?php echo $arrayEnterpriseInfo->bank_account_owner_usd;?>
                            </div>
                        </div>
                        <input type="hidden" value="" id="hd_abtract_value_<?php echo $r_id;?>" />
                        <!--end Payment info-->
                    </div>
                    <div style="width:35%; float:left; text-align:right;" class="inline_block cart_bottom amount">
                        <div>
                        	<label><?php echo $this->translator('cart_subtotal_amount')?></label>: 
                        	<?php echo $subtotalSorted;?> <i><?php echo $p_currency;?></i>
                       	</div>
                        <div id="shipping_amount_cart_<?php echo $r_id;?>">
                        	<label><?php echo $this->translator('cart_shipping_amount')?></label>: 
                        	<?php echo $shipping_priceSorted;?> <i><?php echo $p_currency;?></i>
                        </div>
                        <div id="subtotal_add_shipping_<?php echo $r_id;?>">
                        	<label><?php echo $this->translator('cart_total_amount')?></label>: 
                        	<?php echo $subtotalSorted + $shipping_priceSorted;?> <i><?php echo $p_currency;?></i>
                        </div>
                        <div id="subtotal_subtract_shipping_<?php echo $r_id;?>" style="display: none;">
                        	<label><?php echo $this->translator('cart_total_amount')?></label>: 
                        	<?php echo $subtotalSorted;?> <i><?php echo $p_currency;?></i>
                        </div>
                    </div>
                    <div style="clear:both;"></div>
                    <div>
                        <div><?php echo $this->translator('shoppingcart_review_notice');?>:</div>
                        <textarea name="cart_notice_<?php echo $r_id;?>" style="width:416px; height:120px;"></textarea>
                    </div>
                    <script>
						// Phuong thuc nhan hang
						$("#reception_method_<?php echo $r_id;?>").change(function() {
							var reception_value = $(this).val();
							if(reception_value == "home_delivery")
							{
								$("#shipping_amount_cart_<?php echo $r_id;?>").show("fast");  
								$("#subtotal_subtract_shipping_<?php echo $r_id;?>").hide("fast"); 
								$("#subtotal_add_shipping_<?php echo $r_id;?>").show("fast");                   			
							}
							else
							{
								$("#shipping_amount_cart_<?php echo $r_id;?>").hide("fast");  
								$("#subtotal_add_shipping_<?php echo $r_id;?>").hide("fast");                  		
								$("#subtotal_subtract_shipping_<?php echo $r_id;?>").show("fast");
							}
						});
					</script>
                </div>
            </div>
            <?php endforeach;?>
            <div class="inline_block">
                <div class="col_33"><a href="<?php echo $this->url(array(),'shoppingcart_shoppingcart_list');?>"><?php echo $this->translator('cart_update_cart');?></a></div>
                <div class="col_33" style="text-align:center;"><a href="<?php echo $this->url(array(),'shop_product_all_products');?>"><?php echo $this->translator('cart_continue_button');?></a></div>
                <?php if($this->is_full && $this->is_login):?>
                <div class="col_33" style="text-align:right;"><input type="submit" value="<?php echo $this->translator('cart_order_button');?>" /></div>
                <?php endif;?>
            </div>
        </form>
        <?php endif;?>
    </div>
    <div class="grid_4 omega">
        <?php if($this->is_login):?>
            <?php
                $user = $this->user;
                $customer = $this->customer;
            ?>
            <div class="t_bizprofile_register">
                <!--Billing-->
                <h2><?php echo $this->translator('checkout_billing_address'); ?></h2>

                <div style="text-align:right"><a href="<?php echo $this->url(array(), 'shoppingcart_shoppingcart_checkout');?>"><?php echo $this->translator('review_info_edit');?></a></div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_fullname'); ?>:</label>
                    <?php echo isset($user->full_name)?$user->full_name:null;?>
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_email'); ?>:</label>
                    <?php echo isset($user->email)?$user->email:null;?>
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_full_address'); ?>:</label>
                    <?php echo isset($customer->customer_address)?$customer->customer_address:null;?>
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_city'); ?>:</label>
                    <?php echo isset($customer->customer_city)?$customer->customer_city:null;?>
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_tel'); ?>:</label>
                    <?php echo isset($customer->customer_tel)?$customer->customer_tel:null;?>
                </div>

                <div class="clearfix"></div>
                <!--Shipping-->
                <h2><?php echo $this->translator('checkout_shipping_address'); ?></h2>

                <div style="text-align:right"><a href="<?php echo $this->url(array(), 'shoppingcart_shoppingcart_checkout');?>"><?php echo $this->translator('review_info_edit');?></a></div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_fullname'); ?>:</label>
                    <?php echo isset($customer->shipping_name)?$customer->shipping_name:null;?>
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_email'); ?>:</label>
                    <?php echo isset($customer->shipping_email)?$customer->shipping_email:null;?>
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_full_address'); ?>:</label>
                    <?php echo isset($customer->shipping_address)?$customer->shipping_address:null;?>
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_city'); ?>:</label>
                    <?php echo isset($customer->shipping_city)?$customer->shipping_city:null;?>
                </div>

                <div class="clearfix">
                    <label><?php echo $this->translator('checkout_tel'); ?>:</label>
                    <?php echo isset($customer->shipping_tel)?$customer->shipping_tel:null;?>
                </div>
            </div>
            <?php if(!$this->is_full):?>
            <div style="color:#FF0000">
                <?php echo $this->translator('cart_no_full_info_yet');?>
            </div>
            <?php endif;?>
        <?php else:?>
            <div style="color:#FF0000">
                <?php echo $this->translator('cart_no_login_yet');?>
            </div>
        <?php endif;?>
    </div>
</div>

                    
<script type="text/javascript" >
    $(document).ready(function(){
        // initialize tooltip
        $(".view_detail img[title],label[title]").tooltip({

            // tweak the position
            offset: [10, 2],

            // use the "slide" effect
            effect: 'slide'

        // add dynamic plugin with optional configuration for bottom edge
        }).dynamic({ bottom: { direction: 'down', bounce: true } });

        $('.sb_payment').change(function(){
            rel = $(this).attr('rel');            
            value = $(this).val();
            old_value = $('#hd_abtract_value_'+rel).attr('value');

            $('#payment_info_'+value+'_'+rel).show();
            $('#payment_info_'+old_value+'_'+rel).hide();

            /**
            * Update value again
            */
            $('#hd_abtract_value_'+rel).attr('value', value);
        })

        /**
        * Validate form
        */
        $('#orderForm').validate({
            rules: {
                <?php foreach($this->arrayEnterpriseId as $v_id):?>
                payment_method_<?php echo $v_id;?>: {
                    required: true
                },
                reception_method_<?php echo $v_id;?>: {
                    required: true
                },
                <?php endforeach;?>
            },
            messages:{
                <?php foreach($this->arrayEnterpriseId as $v_id):?>
                payment_method_<?php echo $v_id;?>: {
                    required: "<?php echo $this->translator('payment_method_required');?>"
                },
                reception_method_<?php echo $v_id;?>: {
                    required: "<?php echo $this->translator('reception_method_required');?>"
                },
                <?php endforeach;?>
            }
        });
    })
</script>